package com.zhdl.common.ytools.springContext.impl;

import com.zhdl.common.ytools.springContext.CommonParmaOpt;
import com.zhdl.common.ytools.springContext.request.CommonParamOptReq;
import com.zhdl.hardware_contact.hardware_common.service.CurrencyCmdSendService;
import com.zhdl.hardware_contact.hardware_config.entity.ProjectConfiguration;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.zhdl.common.ytools.springContext.CommonParmaOpt.modbusTcp;

@Slf4j
@Service(modbusTcp)
public class ModbusTcpParamOptImpl implements CommonParmaOpt {
    @Resource
    private CurrencyCmdSendService currencyCmdSendService;

    @Synchronized
    @Override
    public int paramOpt(ProjectConfiguration projectConfiguration, String port) {
        log.info("projectConfiguration:{},ip:{}", projectConfiguration,port);
        CommonParamOptReq commonParamOptReq = new CommonParamOptReq();
        commonParamOptReq.setCheckFunction(modbusTcp);
        commonParamOptReq.setCheckCode("06");
        commonParamOptReq.setCheckPort(port);
        commonParamOptReq.setProjectConfiguration(projectConfiguration);
        currencyCmdSendService.sendCmdFromOpt(commonParamOptReq);
        return 0;
    }
}
